package cn.tedu.truetaste.service.impl;

import cn.tedu.truetaste.mapper.CodeMapper;
import cn.tedu.truetaste.pojo.dto.CodeAddNewDTO;
import cn.tedu.truetaste.pojo.dto.CodeUpdateDTO;
import cn.tedu.truetaste.pojo.vo.CodeListItemVO;
import cn.tedu.truetaste.pojo.vo.CodeStandardVO;
import cn.tedu.truetaste.service.ICodeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class CodeServiceImpl implements ICodeService {

    @Autowired
    private CodeMapper codeMapper;

    @Override
    public void addNew(CodeAddNewDTO codeAddNewDTO) {
        log.debug("开始处理【添加相册】的业务，参数：{}", codeAddNewDTO);
        // 检查餐桌id是否已经被占用
        Integer tableId = codeAddNewDTO.getTableId();
        /*int count = codeMapper.(name);
        if (countByName > 0) {
            // 如果已经被占用，抛出异常
            String message = "添加相册失败，相册名称已经被占用！";
            log.warn(message);
            throw new ServiceException(ServiceCode.ERR_CONFLICT, message);
        }

        // 创建Album对象
        Album album = new Album();
        // 补全Album对象中的属性值：来自参数albumAddNewDTO
        // album.setName(albumAddNewDTO.getName());
        // album.setDescription(albumAddNewDTO.getDescription());
        // album.setSort(albumAddNewDTO.getSort());
        BeanUtils.copyProperties(albumAddNewDTO, album);
        // 执行插入数据：albumMapper.insert(album)
        log.debug("即将插入数据，参数：{}", album);
        int rows = albumMapper.insert(album);
        if (rows!=1){
            String message = "添加相册失败，服务器忙，请稍后再次尝试！";
            log.warn(message);
            throw new ServiceException(ServiceCode.ERR_INSERT,message);
        }*/
    }

    @Override
    public void delete(Long id) {

    }

    @Override
    public void updateInfoById(Long id, CodeUpdateDTO codeUpdateDTO) {

    }

    @Override
    public CodeStandardVO getStandardById(Long id) {
        return null;
    }

    @Override
    public List<CodeListItemVO> list() {
        return null;
    }
}
